﻿namespace Attacher
{
	using System;
	using System.ComponentModel;

	/// <summary>
	/// This class responsibility is to be the base of all those classes
	/// that can inform when one of its properties has changed.
	/// </summary>
	public abstract class PropertyChangedNotifier : INotifyPropertyChanged
	{
		#region Events

		/// <summary>
		/// Informs that a property has changed its value
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;

		#endregion

		#region Public Methods

		/// <summary>
		/// Informs that the property passed as argument has changed its value.
		/// </summary>
		/// <param name="propertyName">the name of the property that changed its value.</param>
		/// <exception cref="ArgumentNullException">Occurs if the propertyName is <c>null</c> or empty.</exception>
		protected virtual void OnPropertyChanged(string propertyName)
		{
			ParameterChecker.IsNotNullOrEmpty(propertyName, "propertyName");

			PropertyChangedEventHandler handler = this.PropertyChanged;
			if (handler != null)
			{
				handler.Invoke(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		#endregion
	}
}
